package com.my.attendance.controller;

import com.my.attendance.entity.Position;
import com.my.attendance.service.ZhiChengService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ZhiChengAdd")
public class ZhiChengAdd extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            String position_number = req.getParameter("position_number");
            String name = req.getParameter("name");
            String level = req.getParameter("level");
            String notes = req.getParameter("notes");
            ZhiChengService zhiChengService = new ZhiChengService();
            Position position = new Position();
            position.setPosition_number(Integer.parseInt(position_number));
            position.setName(name);
            position.setLevel(level);
            position.setNotes(notes);
            zhiChengService.addPos(position);
            req.getRequestDispatcher("ZhiChengList").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
